#!/bin/sh
export SCRIPTPATH
SCRIPTPATH="$( cd "$(dirname "$0")" || exit; pwd -P )"

# Down the last running theme
if [ -f "/tmp/leftwm-theme-down" ]; then
    /tmp/leftwm-theme-down
    rm /tmp/leftwm-theme-down
fi
ln -s "$SCRIPTPATH"/down /tmp/leftwm-theme-down

# # Boot picom or compton if it exists
# picom --experimental-backends > /dev/null &

~/.config/leftwm/scripts/autostart.sh

# Set the theme.toml config
leftwm command "LoadTheme $SCRIPTPATH/theme.toml"

# Set background
feh --bg-fill "$SCRIPTPATH"/background.jpg

dunst &

index=0
leftwm-state -q -n -t "$SCRIPTPATH"/sizes.liquid | sed -r '/^\s*$/d' | while read -r width
do
  barname="mainbar$index"
  monitor="$(polybar -m | awk -v i="$(( index + 1 ))" 'NR==i{print}' | sed s/:.*// | tr -d '\n')"
  monitor=$monitor width=$(( width - 16 )) polybar -c "$SCRIPTPATH"/polybar.config $barname &
  index=$((index+1))
done
